package com.small.nine.wxmp.domain.bean.wx.msg;

import com.small.nine.wxmp.common.constant.WxConstant;
import com.small.nine.wxmp.utils.wx.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 回复音乐消息
 *
 * @author sheng_zs@126.com
 * @date 2021-08-02 17:49
 */
@Data
@EqualsAndHashCode(callSuper = true)
@XStreamAlias("xml")
public class WxMusicMsgBean extends WxOutMsgBaseBean {
    private static final long serialVersionUID = 1L;

    /**
     * Music 节点
     */
    @XStreamAlias("Music")
    private MusicBean music;

    @Override
    public String toXml() {
        return XmlUtils.beanToXml(this);
    }

    /**
     * 初始化
     *
     * @param toUser       接收者，openID
     * @param fromUser     发送者
     * @param createTime   时间戳
     * @param title        标题
     * @param description  音乐描述
     * @param musicUrl     音乐链接
     * @param hQMusicUrl   高质量音乐链接
     * @param thumbMediaId 缩略图的媒体id
     * @return WxMusicMsgBean
     */
    public static WxMusicMsgBean getInstance(String toUser, String fromUser, Long createTime, String title,
                                             String description, String musicUrl, String hQMusicUrl, String thumbMediaId) {
        WxMusicMsgBean messageBean = new WxMusicMsgBean();
        messageBean.setToUserName(toUser);
        messageBean.setFromUserName(fromUser);
        messageBean.setMsgType(WxConstant.MSG_TYPE_MUSIC);
        messageBean.setCreateTime(createTime);
        messageBean.setMusic(MusicBean.getInstance(title, description, musicUrl, hQMusicUrl, thumbMediaId));
        return messageBean;
    }
}
